<?php
namespace App\Hydrators;

use App\Models\Absence;
use App\Models\User;

/**
 * @SuppressWarnings(CyclomaticComplexity)
 * @SuppressWarnings(NPathComplexity)
 */
class AbsenceHydrator extends Hydrator
{

    public function __construct()
    {
        parent::__construct();
    }

    /**
     * @return array
     */
    public function getCreateRules()
    {
        return [
            'user_id'           => 'required',
            'absence_date'      => 'required',
            'start_time'        => 'required',
            'end_time'          => 'required',
            'absence_note'        => 'required',
            'absence_type'        => 'required',

        ];
    }

    /**
     * @return array
     */
    public function getUpdateRules()
    {

    }


    public function hydrateForCreate($incoming, $model)
    {
        if (isset($incoming->user_id)) {
            User::findOrFail($incoming->user_id);
            $model->user_id = $incoming->user_id;
        }

        if (isset($incoming->absence_date)) {
            $model->absence_date = $incoming->absence_date;
        }

        if (isset($incoming->start_time)) {
            $model->start_time = $incoming->start_time;
        }

        if (isset($incoming->end_time)) {
            $model->end_time = $incoming->end_time;
        }

        if (isset($incoming->absence_note)) {
            $model->absence_note = $incoming->absence_note;
        }

        if (isset($incoming->absence_type)) {
            $model->absence_type = $incoming->absence_type;
        }
        $model->save();
        return $model;
    }

    public function hydrateForUpdate($incoming, $model)
    {
        
    }
}
